//
//  Train. 选择排序.swift
//  LeetCodeTrain
//
//  Created by rjb on 2021/7/18.
//  Copyright © 2021 rjb. All rights reserved.
//

import Foundation
/*
 前面是有序的，后面是无序的
 从后面选择合适的放入前面的
 **/
class SolutionSelectSortTrain {
    func selectSort(_ nums: inout [Int]) {
        for i in 0..<nums.count {
            var minIndex = i
            for j in i..<nums.count {
                if nums[j] < nums[minIndex] {
                    minIndex = j
                }
            }
            let tmp = nums[i]
            nums[i] = nums[minIndex]
            nums[minIndex] = tmp
        }
    }
    static func test() {
        var nums = [156,141,35,94,88,61,111]
        let solution = SolutionSelectSortTrain()
        solution.selectSort(&nums)
        print(nums)
    }
}
